<?php
/**
 * Author: lf
 * Blog: https://blog.szdma.com
 * Email: job@szdma.com
 * Created at: 2016-03-23 15:49
 */

/**
 * @var $this yii\web\View
 * @var $model backend\models\Article
 */

use backend\widgets\ActiveForm;
use backend\models\Category;
use common\libs\Constants;
use backend\widgets\JsBlock;
use backend\widgets\ueditor\UEditor;

use backend\assets\plugins\ICheckAsset;

ICheckAsset::register($this);

$this->title = "Articles";

?>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <?php $form = ActiveForm::begin(
                [
                    'options' => [
                        'enctype' => 'multipart/form-data',
                        'class'   => 'form-horizontal m-t',
                    ],
                ]
            ); ?>
            <div class="ibox-content">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">通用</a>
                        </li>
                        <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">扩展</a>
                        </li>
                    </ul>
                    <div class="tab-content">

                        <div id="tab-1" class="tab-pane active">
                            <div class="panel-body">
                                <!--left start-->
                                <div class="form-group">
                                    <?= $form->field($model, 'article_category_id')->label(yii::t('app', 'Category'))->dropDownList(
                                        Category::getCategoriesName()
                                    ) ?>
                                    <?= $form->field($model, 'title')->textInput(); ?>
                                    <?= $form->field($model, 'sub_title')->textInput(); ?>
                                    <?= $form->field($model, 'summary')->textArea(); ?>
                                    <?= $form->field($model, 'content')->widget(Ueditor::className(), []) ?>
                                    <?php $hide = ' hide ';
                                    if ($model->visibility == Constants::ARTICLE_VISIBILITY_SECRET) {
                                        $hide = '';
                                    } ?>
                                    <?= $form->field($model, 'password', ['options' => ['class' => "form-group $hide"]])->textInput(); ?>
                                    <?= $form->defaultButtons(['size' => 12]) ?>
                                </div>
                                <!--left stop -->
                            </div>
                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="panel-body">
                                <div class="form-group">
                                    <?= $form->field($model, 'thumb')->imgInput(
                                        ['style' => 'max-width:200px; max-height:200px', 'default' => $assets_url.'/images/none.jpg']
                                    ); ?>
                                </div>
                                <!--属性设置start-->
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?= yii::t('app', 'Attributes') ?>
                                    </label>
                                    <div class="col-sm-10">
                                        <?= $form->field($model, 'flag_headline')->checkbox() ?>
                                        <?= $form->field($model, 'flag_recommend')->checkbox() ?>
                                        <?= $form->field($model, 'flag_slide_show')->checkbox() ?>
                                        <?= $form->field($model, 'flag_special_recommend')->checkbox() ?>
                                        <?= $form->field($model, 'flag_roll')->checkbox() ?>
                                        <?= $form->field($model, 'flag_bold')->checkbox() ?>
                                        <?= $form->field($model, 'flag_picture')->checkbox() ?>
                                    </div>
                                </div>
                                <!--属性设置stop-->
                                <!--seo设置start-->
                                <div class="form-group">
                                    <?= $form->field($model, 'seo_title')->textInput(); ?>
                                    <?= $form->field($model, 'seo_keywords')->textInput(); ?>
                                    <?= $form->field($model, 'seo_description')->textInput(); ?>
                                </div>
                                <!--seo设置stop-->
                                <!--其他start-->
                                <div class="form-group">
                                    <?= $form->field($model, 'status')->dropDownList(Constants::getArticleStatus()); ?>
                                    <?= $form->field($model, 'can_comment')->dropDownList(Constants::getYesNoItems()); ?>
                                    <?= $form->field($model, 'visibility')->dropDownList(Constants::getArticleVisibility()); ?>
                                </div>
                                <!--其他stop-->
                                <div class="form-group">
                                    <?= $form->field($model, 'tag')->textInput(); ?>
                                    <?= $form->field($model, 'sort')->textInput(); ?>
                                    <?= $form->defaultButtons(['size' => 12]) ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php $form = ActiveForm::end() ?>
        </div>
    </div>
</div>

<?php JsBlock::begin() ?>
<script>
  $(document).ready(function () {
    $('select#article-visibility').change(function () {
      if ($(this).val() == <?=Constants::ARTICLE_VISIBILITY_SECRET?>) {
        $('div.field-article-password').removeClass('hide')
      }
      else {
        $('div.field-article-password').addClass('hide')
      }
    })
    $('.i-checks').iCheck({
      checkboxClass: 'icheckbox_square-green',
      radioClass: 'iradio_square-green',
    })
  })
</script>
<?php JsBlock::end() ?>
